Skip to content

Fix iOS build: form owned-userdata release callback from a closure literal - #8897

Merged
azooz2003-bit merged 1 commit into
mainfrom
fix-ios-release-cfnptr
Jul 25, 2026
Merged

azooz2003-bit merged 1 commit into
mainfrom
fix-ios-release-cfnptr

Conversation

@azooz2003-bit

@azooz2003-bit azooz2003-bit commented Jul 25, 2026 •

Copy link
Copy Markdown
Collaborator

Main's iOS build is red since f41507e (an untested "cmux reload-cloud"-authored commit): it passes the static method GhosttySurfaceBridge.releaseRetainedOpaque directly as a C function pointer to ghostty_surface_new_with_owned_userdata, which Swift only permits for global funcs or capture-free closure literals. Every CmuxMobileTerminal compile fails, which killed internal TestFlight run 30139324698 (and blocks all iOS uploads). This wraps the callback in a capture-free closure literal forwarding to the same method; no behavior change. Verified against the language rule and gated on a local GhosttyKit rebuild before merge.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes the iOS build by forming the owned-userdata release callback as a capture‑free closure literal when calling ghostty_surface_new_with_owned_userdata instead of passing the static method reference. This follows Swift’s C function pointer rules and restores CmuxMobileTerminal iOS builds and TestFlight uploads with no behavior change.

Written for commit a47e2fc. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved surface cleanup callback handling to ensure resources are released reliably when a terminal surface is closed.

…e literal

Commit f41507e passed the static method
GhosttySurfaceBridge.releaseRetainedOpaque directly to
ghostty_surface_new_with_owned_userdata, but Swift forms C function
pointers only from global funcs or capture-free closure literals, so
every iOS build of CmuxMobileTerminal fails, including the internal
TestFlight lane. Wrap the call in a capture-free literal that forwards
to the same method; behavior is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f369e15d-308f-4074-a4da-98e368afe885

📥 Commits

Reviewing files that changed from the base of the PR and between 46cc01f and a47e2fc.

📒 Files selected for processing (1)
  • Packages/iOS/CmuxMobileTerminal/Sources/CmuxMobileTerminal/GhosttySurfaceView.swift

📝 Walkthrough

Walkthrough

GhosttySurfaceView now supplies the userdata-release callback to ghostty_surface_new_with_owned_userdata as a capture-free closure calling GhosttySurfaceBridge.releaseRetainedOpaque.

Changes

Surface callback

Layer / File(s) Summary
Capture-free userdata release callback
Packages/iOS/CmuxMobileTerminal/Sources/CmuxMobileTerminal/GhosttySurfaceView.swift
The surface creation call uses a capture-free closure for releasing retained opaque userdata.
Estimated code review effort: 1 (Trivial) ~2 minutes

Suggested reviewers: lawrencecchen

🚥 Pre-merge checks | ✅ 25
✅ Passed checks (25 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing the iOS build by using a closure literal for the owned-userdata release callback.
Description check ✅ Passed The description includes a solid summary and testing notes; the remaining template sections are mostly non-critical for this code fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Cmux Swift Actor Isolation ✅ Passed Diff only replaces a static method reference with a capture-free C callback closure; it adds no new MainActor, Sendable, or UI-store isolation issue.
Cmux Swift Blocking Runtime ✅ Passed Diff only wraps a C callback in a capture-free closure; no waits, sleeps, syncs, polling, or locks were added.
Cmux Browser Automation Off-Main ✅ Passed PR only changes GhosttySurfaceView.swift C callback wiring; no browser socket automation, policy switch, or tests were touched.
Cmux Expensive Synchronous Load ✅ Passed Diff only swaps a C callback to a capture-free closure in GhosttySurfaceView; it adds no agent-history/JSON/load work on main actor or interactive paths.
Cmux Cache Substitution Correctness ✅ Passed Diff only wraps a C callback for userdata teardown; no fresh-authoritative read is replaced by a cached/stale value in persistence/history/undo/snapshot logic.
Cmux No Hacky Sleeps ✅ Passed The only change is a Swift closure-literal callback wrapper; no sleeps, timers, polling, or wall-clock waits were added.
Cmux Algorithmic Complexity ✅ Passed Only change in GhosttySurfaceView.swift:3476-3490 is a capture-free C callback wrapper; no collection scans, sorting, or hot-path algorithm changes.
Cmux Swift Concurrency ✅ Passed Diff only wraps a third-party C userdata-release callback in a capture-free closure; no new DispatchQueue/Task/Combine or other legacy async pattern is introduced.
Cmux Swift @Concurrent ✅ Passed The change only wraps a C callback in a capture-free closure; it adds no @concurrent/nonisolated async code or UI-heavy async call sites.
Cmux Swift Package Boundaries ✅ Passed Only a capture-free C callback bridge in GhosttySurfaceView/GhosttySurfaceBridge; it’s app-target Ghostty glue, not reusable domain logic.
Cmux Swiftpm Lockfiles ✅ Passed Diff only changes a Swift source file; no Package.swift, .gitignore, workflow, or Xcode dependency files were touched, so the lockfile rule doesn’t apply.
Cmux Swift Logging ✅ Passed The diff only wraps the callback in a capture-free closure; it adds no print/debugPrint/dump/NSLog, and the existing file-scoped Logger predates the PR.
Cmux User-Facing Error Privacy ✅ Passed Diff only changes the Ghostty callback wiring; no user-facing errors, alerts, output copy, or disallowed details were added or altered.
Cmux Full Internationalization ✅ Passed The change only wraps a Ghostty C callback in a capture-free closure; it adds no user-facing Swift/web text or catalog/routing updates.
Cmux Swiftui State Layout ✅ Passed Diff only wraps a C callback in GhosttySurfaceView (a UIKit bridge); no new SwiftUI state/layout patterns were introduced.
Cmux Architecture Rethink ✅ Passed A small platform-bridge fix: the C callback is wrapped in a capture-free closure, with no new timing, ownership, or lifecycle state.
Cmux Swift Auxiliary Window Close Shortcuts ✅ Passed Touched code is a UIView surface callback change, not a standalone NSWindow/WindowGroup; no cmux identifier or close-shortcut ownership was added or altered.
Cmux Source Artifacts ✅ Passed Only changed path is an intentional Swift source file; diff tweaks a callback and adds no artifacts, temp files, caches, or generated outputs.
Cmux No Test Or Debug Seam In Production Source ✅ Passed The diff only wraps a C callback in a capture-free closure; it adds no #if DEBUG, test hook, or visibility-widening seam in production Sources.
Cmux No Ambient Global State ✅ Passed Diff only wraps an existing callback in a capture-free closure inside makeSurface; it adds no new top-level globals, statics, or singleton state.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ios-release-cfnptr

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a Swift compiler error on iOS introduced by a prior commit that passed a static method reference directly as a C function pointer argument to ghostty_surface_new_with_owned_userdata. Swift only permits C function pointers to be formed from global functions or capture-free closure literals, not static method references.

  • The fix wraps GhosttySurfaceBridge.releaseRetainedOpaque in a capture-free closure literal that forwards the single userdata argument unchanged — identical runtime behavior with no semantic change.
  • releaseRetainedOpaque carries no actor isolation annotation and only calls Unmanaged.release(), so invoking it from a C callback context is safe.

Confidence Score: 5/5

Safe to merge — the change is a one-line mechanical fix that unblocks iOS compilation with no behavioral difference.

The closure is genuinely capture-free, forwards the argument identically, and releaseRetainedOpaque has no actor isolation, so the C-callback invocation path is sound. No rules are violated and no logic is altered.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
Packages/iOS/CmuxMobileTerminal/Sources/CmuxMobileTerminal/GhosttySurfaceView.swift Wraps the static method reference in a capture-free closure literal to satisfy Swift's C function pointer constraint; fix is minimal, correct, and behavior-preserving.

Sequence Diagram

sequenceDiagram
    participant Swift as GhosttySurfaceView (Swift)
    participant C as ghostty_surface_new_with_owned_userdata (C)
    participant Closure as Capture-free closure
    participant Bridge as GhosttySurfaceBridge.releaseRetainedOpaque

    Swift->>Swift: Unmanaged.passRetained(bridge) → bridgePointer
    Swift->>C: "ghostty_surface_new_with_owned_userdata(app, &config, closure)"
    Note over Swift,C: Closure is capture-free — valid C function pointer
    C-->>Swift: ghostty_surface_t (or nil)

    Note over C,Closure: Later, when surface is freed
    C->>Closure: invoke(userdata)
    Closure->>Bridge: releaseRetainedOpaque(userdata)
    Bridge->>Bridge: Unmanaged.fromOpaque(userdata).release()
Loading

Reviews (1): Last reviewed commit: "Fix iOS build: form the owned-userdata r..." | Re-trigger Greptile

@azooz2003-bit
azooz2003-bit merged commit caf2140 into main Jul 25, 2026
6 checks passed
azooz2003-bit added a commit that referenced this pull request Jul 25, 2026
Main's #8897 made the same
toolchain fix as b324e63; the conflict was comment-only and keeps
main's wording.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant